<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>身份证</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<link rel="shortcut icon" href="/favicon.ico">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">

<link rel="stylesheet" href="./css/common.css">
<link rel="stylesheet" href="./css/hardware.css">
<link rel="stylesheet" href="http://g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">

<script src="../js/jquery-1.8.3.min.js"></script>
<script src="./js/zepto.js"></script>
<script src="./js/sm.js"></script>
<script src="./js/sm-extend.js"></script>
<script src="./js/jquery.form.js"></script>
<script type="text/javascript">
window.$$=window.Zepto = Zepto;
</script>
<style>
.check-team{border: 1px solid #d8dcdf;}
.row div{
	border-top: 1px solid #d8dcdf;
	border-right: 1px solid #d8dcdf;
	border-left: 1px solid #d8dcdf;
}
.row{
	border: 1px solid #d8dcdf;
}
.check-team td,th{
	border: 1px solid #d8dcdf;
}
.check-team h5{
	font-size: 14px;
}
</style>
</head>
<body>
	<div class="page">
		<header class="bar bar-nav">
			<a class="button button-link button-nav pull-left" href="javascript:window.history.back();" data-transition='slide-out'>
				<span class="icon icon-left"></span> 返回
			</a>
			<h1 class="title">身份证</h1>
		</header>

	<!-- 主体内容 -->
	<div class="content">
		<div class="D_content--wrap">
			<div id="listItemDiv">
			</div>
			
			<div class="list-remarks">
			<form method="post" enctype="multipart/form-data" id="form1">
						<div id="formContent"></div>
						<div class="progress"
							style="background: green;width: 0;display: none" id="progress">
							<div class="percent">0%</div>
						</div>
						<div id="status" style="display: block"></div>
						<div class="list-inline col-xs-3 piccontent" style="margin:5px;width:90% !important;" >
							<input id="addLogo1" class="btn btn-default btn-sm" type="file" name="zhengmian" style="width: 24%;touch-action: none;">  </input>
							<img id="logopic1" src="../images/idcard1.png" 	style="margin-top: 20px;"> </input>
						</div>
						<div class="list-inline col-xs-3 piccontent" style="margin:5px;width:90% !important;" >
							<input id="addLogo2" class="btn btn-default btn-sm" type="file" name="fanmian" style="width: 24%;touch-action: none;">  </input>
							<img id="logopic2" src="../images/idcard2.png" 	style="margin-top: 20px;"> </input>
						</div>
					</form>
			</div>
<!-- 			<p style="position: fixed;left: 5%;width: 90%"><a href="javaScript:addpic()" class="button button-success">添加图片</a></p> -->
			<!-- 保存 -->
			<div class="D_reserve--footer" style="position: fixed; bottom: 10px; width: -webkit-fill-available;">
				<a href="javascript:toSave();" class="D_reserve--btn" id="save" style="display: none;  ">保存</a>
				<a href="javascript:toUpdate();" class="D_reserve--btn" id="update" style="display: none;float: left;width: 45%">修改</a>
				<a href="javascript:todel();" class="D_reserve--btn" id="del" style="display: none;float: right;width: 45%;background: red">删除</a>
			</div>
		</div>
		
		
	</div>
</div>

<script src="../js/common.js"></script>
<script src="./js/checkList.js"></script>
<script type="text/javascript">
var type = 1; 	//1:验房清单清单项
var userId = $.getUrlParam("userId");	//所选租客id或房东id

var inputid="";
var logoid="";
var hasData=false;
$(function(){
	queryDetailById();
	 $(document).on('change', '#addLogo1', function () {
		    function getObjectURL(file) {
		        var url = null;
		        if (window.createObjectURL != undefined) { // basic
		            url = window.createObjectURL(file);
		        } else if (window.URL != undefined) { // mozilla(firefox)
		            url = window.URL.createObjectURL(file);
		        } else if (window.webkitURL != undefined) { // webkit or chrome
		            url = window.webkitURL.createObjectURL(file);
		        }
		        return url;
		    }
		    var objUrl = getObjectURL(this.files[0]);
			$("#logopic1").attr("src",objUrl);
		});
	 $(document).on('change', '#addLogo2', function () {
		    function getObjectURL(file) {
		        var url = null;
		        if (window.createObjectURL != undefined) { // basic
		            url = window.createObjectURL(file);
		        } else if (window.URL != undefined) { // mozilla(firefox)
		            url = window.URL.createObjectURL(file);
		        } else if (window.webkitURL != undefined) { // webkit or chrome
		            url = window.webkitURL.createObjectURL(file);
		        }
		        return url;
		    }
		    var objUrl = getObjectURL(this.files[0]);
			$("#logopic2").attr("src",objUrl);
		});
	if(hasData){
		$("#update").show(); 
		$("#del").show();
		queryDetailById(billsId);
	}else{
		$("#save").show(); 
	}
});

function toSave(){
	 $$.showPreloader('正在上传');
	$('#form1').ajaxSubmit(  
	        {
	            url: '../bills/addIdCard',
	            type: 'post',
	            dataType: 'json',
	            data :{"userId" :userId},
	            beforeSubmit: function () {},
	            success: function (data) {
	            	$$.hidePreloader();
	                if(data.success){
	                	alert("上传成功");
	                	document.location.href = "./zukeKongjian.html";
	                }
	            },
	            error : function (err){
	            	alert("上传失败");
	            	$$.hidePreloader();
	            },
	            clearForm: false,//禁止清楚表单
	            resetForm: false //禁止重置表单
	        });
}
function queryDetailById(){
	$.ajax({
		type : "POST",
		dataType : 'json',
		url : "../certificate/getUserIdCardInfo",
		data : {
			userId: userId
		},
		success : function(data) {
		console.log(data);
		if(data.rows !=null && data.rows.length>0){
			hasData=true;
		}
		
		$("#logopic1").attr("src",data.rows[0]==null?"":data.rows[0].imgUrl);
		$("#logopic2").attr("src",data.rows[1]==null?"":data.rows[1].imgUrl);
		}
	});
}

function toUpdate(){
	 $$.showPreloader('正在上传');
	$('#form1').ajaxSubmit(  
	        {
	            url: '../bills/updateBills?houseId='+$("#houseId").val()+"&bill_name="+$("#bill_name").val(),
	            type: 'post',
	            dataType: 'json',
	            data:{"billsId":billsId,
	            	"userId":userId},
	            beforeSubmit: function () {},
	            success: function (data) {
	            	$$.hidePreloader();
	                if(data.success){
// 	                	var son =  document.getElementById('progress');
	                	alert("修改成功");
	                	document.location.href = "./gasList.html?1=1&userId="+userId;
	                }
	            },
	            error : function (err){
	            	$$.hidePreloader();
	            	alert("修改失败");
	            },
	            clearForm: false,//禁止清楚表单
	            resetForm: false //禁止重置表单
	        });
}

function todel(){
	$.ajax({
		type : "POST",
		dataType : 'json',
		url : "../bills/deleteBills",
		data : {
			id: billsId
		},
		success : function(data) {
		if(data.success){
			$$.alert("删除成功", function(){
				document.location.href = "./gasList.html?1=1&userId="+userId;
			});
			
		}
		}
	});
}
</script>
</body>
</html>